import IdEnumItem from '@/framework/infra/enum/IdEnumItem'

export default class IdEnum {
  static UN_KNOW = new IdEnumItem(null, '')

  static getValues() {
    return Object.values(this)
  }

  static getKeys() {
    return Object.keys(this)
  }

  static getOptions() {
    return this.getValues().map(item => {
      return {
        label: item.name,
        value: item.id,
        extra: item.$extra
      }
    })
  }

  static getNameById(id) {
    const item = this.getById(id)
    if (item) {
      return item.name
    }
    return ''
  }

  static getById(id) {
    if (id !== null && typeof id === 'object') {
      return id
    }
    return this.getValues().find(el => el.id === id) || this.UN_KNOW
  }

  static getByName(name) {
    return this.getValues().find(el => el.name === name) || this.UN_KNOW
  }
}
